home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Dev / misc / temgen.lha / Temgen / tg-0.11 / crc.c < prev    next >
C/C++ Source or Header  |  2002-12-18  |  794b  |  26 lines

  1. #include "crc_table.h"
  2.  
  3. unsigned long crc32(unsigned char *buf, int len)
  4. {
  5.         unsigned char *p;
  6.         unsigned long  crc;
  7.  
  8.         crc = 0xffffffff;       /* preload shift register, per CRC-32 spec */
  9.         for (p = buf; len > 0; ++p, --len)
  10.                 crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p];
  11.         return ~crc;            /* transmit complement, per CRC-32 spec */
  12. }
  13.  
  14. /* for null-terminated strings: */
  15. unsigned long crc32_0(unsigned const char *buf)
  16. {
  17.         unsigned const char *p;
  18.         unsigned long  crc;
  19.  
  20.         crc = 0xffffffff;       /* preload shift register, per CRC-32 spec */
  21.         for (p = buf; *p; ++p)
  22.                 crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p];
  23.         return ~crc;            /* transmit complement, per CRC-32 spec */
  24. }
  25.  
  26.